package com.zlb.app.modules.quartz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zlb.app.common.entity.R;
import com.zlb.app.modules.quartz.entity.Job;
import com.zlb.app.modules.quartz.entity.vo.JobQueryVO;
import com.zlb.app.modules.quartz.entity.vo.JobRunVO;
import com.zlb.app.modules.quartz.entity.vo.JobStatusVO;
import com.zlb.app.modules.quartz.service.IJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 定时任务调度表 控制层
 * @Author zWX1367238
 * @Date 2024-08-27 11:51:15
 */
@RestController
@RequestMapping("/job")
@RequiredArgsConstructor
@Api(tags = "定时任务调度表")
public class JobController {

    private final IJobService jobService;

    @GetMapping("/page")
    @ApiOperation("分页查询定时任务调度表数据")
    public R<IPage<Job>> page(JobQueryVO vo) {
        return R.ok(this.jobService.pages(vo));
    }

    @PostMapping
    @ApiOperation("新增定时任务调度")
    public R<Boolean> saveJob(@RequestBody Job job) {
        return R.ok(this.jobService.saveJob(job));
    }

    @PutMapping
    @ApiOperation("修改定时任务调度")
    public R<Boolean> updateJob(@RequestBody Job job) {
        return R.ok(this.jobService.updateJob(job));
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("根据id集合删除定时任务调度表")
    public R<Boolean> deleteJobs(@PathVariable("ids") Long[] ids) {
        return R.ok(this.jobService.deleteJobs(ids));
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id获取任务")
    public R<Job> getJobById(@PathVariable("id") Long id) {
        return R.ok(this.jobService.getJobById(id));
    }

    @ApiOperation("更改任务的状态")
    @PutMapping("/update/status")
    public R<Boolean> updateJobStatus(@RequestBody JobStatusVO jobStatusVO) {
        return R.ok(this.jobService.updateJobStatus(jobStatusVO));
    }
    @ApiOperation("执行一次某个任务")
    @PutMapping("/run")
    public R<Boolean> runJob(@RequestBody JobRunVO jobRunVO) {
        return R.ok(this.jobService.runJob(jobRunVO));
    }


}
